package com.zzk.lanouhn.myapplication1.adapters;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;
import com.zzk.lanouhn.myapplication1.R;
import com.zzk.lanouhn.myapplication1.activity.ArticlesListDetailsActivity;
import com.zzk.lanouhn.myapplication1.activity.CollectArticlesDetailsActivity;
import com.zzk.lanouhn.myapplication1.activity.ThreeSifeSecondActivity;
import com.zzk.lanouhn.myapplication1.modles.CollectArticles;

import java.util.List;

/**
 * 作者个人信息页面->收藏->文章适配器
 * Created by lanouhn on 16/9/10.
 */
public class AuthorsCollectArticlesAdapter extends RecyclerView.Adapter<AuthorsCollectArticlesAdapter.collectViewHolder>{

    private Context context;
    private List<CollectArticles.DataBean.TopicBean> collectDetails;

    public AuthorsCollectArticlesAdapter(Context context, List<CollectArticles.DataBean.TopicBean> collectDetails) {
        this.context = context;
        this.collectDetails = collectDetails;
    }

    @Override
    public collectViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(context).inflate(R.layout.item_author_collect_articles,null);
        collectViewHolder holder=new collectViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(collectViewHolder holder, final int position) {
        CollectArticles.DataBean.TopicBean bean=collectDetails.get(position);
        holder.tv_title_collect.setText(bean.getTitle());
        holder.tv_likes.setText(bean.getLikes());
        holder.tv_collect_time.setText(bean.getDatestr_lify()+" 收藏");
        if (!bean.getPic().equals("")) {
            Picasso.with(context).load(bean.getPic()).into(holder.iv_pic_act);
        } else {
            Picasso.with(context).load(bean.getPics().get(0).getUrl()).into(holder.iv_pic_act);
        }
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if (collectDetails.get(position).getType().equals("")&&collectDetails.get(position).getType_id().equals("")) {
                    Intent intent=new Intent(context, CollectArticlesDetailsActivity.class);
                    Bundle bundle=new Bundle();
                    bundle.putString("收藏文章内容",collectDetails.get(position).getId());
                    intent.putExtras(bundle);
                    context.startActivity(intent);
                }
                if (collectDetails.get(position).getType().equals("2")&&collectDetails.get(position).getType_id().equals("1")) {
                    Intent intent=new Intent(context, ArticlesListDetailsActivity.class);
                    Bundle bundle=new Bundle();
                    bundle.putString("内容",collectDetails.get(position).getId());
                    intent.putExtras(bundle);
                    context.startActivity(intent);
                }
                if (collectDetails.get(position).getType_id().equals("")&&collectDetails.get(position).getType().equals("5")) {
                    Intent intent=new Intent(context, ThreeSifeSecondActivity.class);
                    intent.putExtra("item_ID",collectDetails.get(position).getId());
                    context.startActivity(intent);
                }

            }
        });

    }

    @Override
    public int getItemCount() {
        return collectDetails.size();
    }

    public class collectViewHolder extends RecyclerView.ViewHolder{
        private ImageView iv_pic_act;
        private TextView tv_title_collect,tv_likes,tv_collect_time;
        public collectViewHolder(View itemView) {
            super(itemView);
            iv_pic_act= (ImageView) itemView.findViewById(R.id.iv_icon_pic_articles);
            tv_title_collect= (TextView) itemView.findViewById(R.id.tv_article_title_collect);
            tv_likes= (TextView) itemView.findViewById(R.id.tv_likes_articles_collect);
            tv_collect_time= (TextView) itemView.findViewById(R.id.tv_time_collect);
        }
    }
}
